package cn.fuxi2022.module.passage.controller;


import cn.fuxi2022.core.utils.PageUtils;
import cn.fuxi2022.model.empty.applets.GroupPassage;
import cn.fuxi2022.model.resp.R;
import cn.fuxi2022.module.passage.service.GroupPassageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 * 公众号文章（小程序供用户查看） 前端控制器
 * </p>
 *
 * @author fuxi
 * @since 2022-10-09 10:32:56
 */
@RestController
@RequestMapping("/admin/passage")
public class GroupPassageController {
    @Autowired
    private GroupPassageService groupPassageService;


    /**
     * 列表
     */
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params) {
        PageUtils page = groupPassageService.queryPage(params);

        return R.ok().data(page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        GroupPassage groupPassage = groupPassageService.getById(id);

        return R.ok().data("groupPassage", groupPassage);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody @Validated(GroupPassage.Save.class) GroupPassage groupPassage) {
        groupPassageService.save(groupPassage);

        return R.ok("保存文章成功");
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody @Validated(GroupPassage.Update.class) GroupPassage groupPassage) {
        groupPassageService.updateById(groupPassage);

        return R.ok("修改文章成功");
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] ids) {
        groupPassageService.removeByIds(Arrays.asList(ids));

        return R.ok("删除文章成功");
    }
}
